using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;

namespace DriverSVH
{
    public struct SVHControllerFeedback
    {
        //! Returned position value of the motor [Ticks]
        public int position;
        //! Returned current value of the motor [mA]
        public short current;

        public SVHControllerFeedback(Int32 p = 0,short c=0)
        {
            position = p;
            current = c;
        }
    }

    public struct SVHControllerFeedbackAllChannels
    {
        //! Multiple controllcommands that shall be send at once
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
        public SVHControllerFeedback[] feedbacks;

        /**
         * \brief Constructs a controllcommand adressing all channels at once All
         * \param _feedback0 Target position for the Thumb_Flexion
         * \param _feedback1 Target position for the Thumb_Opposition
         * \param _feedback2 Target position for the Index_Finger_Distal
         * \param _feedback3 Target position for the Index_Finger_Proximal
         * \param _feedback4 Target position for the Middle_Finger_Distal
         * \param _feedback5 Target position for the Middle_Finger_Proximal
         * \param _feedback6 Target position for the Ring_Finger
         * \param _feedback7 Target position for the Pinky
         * \param _feedback8 Target position for the Finger_Spread
        **/
        public SVHControllerFeedbackAllChannels(SVHControllerFeedback[] _feedbacks)
        {
            feedbacks = new SVHControllerFeedback[]
            {
                _feedbacks[0],
                _feedbacks[1],
                _feedbacks[2],
                _feedbacks[3],
                _feedbacks[4],
                _feedbacks[5],
                _feedbacks[6],
                _feedbacks[7],
                _feedbacks[8]
            };
        }

        public SVHControllerFeedbackAllChannels(SVHControllerFeedback _feedback0, SVHControllerFeedback _feedback1, SVHControllerFeedback _feedback2,
                                                SVHControllerFeedback _feedback3, SVHControllerFeedback _feedback4, SVHControllerFeedback _feedback5,
                                                SVHControllerFeedback _feedback6, SVHControllerFeedback _feedback7, SVHControllerFeedback _feedback8)
        {
            feedbacks = new SVHControllerFeedback[]
            {
                _feedback0,
                _feedback1,
                _feedback2,
                _feedback3,
                _feedback4,
                _feedback5,
                _feedback6,
                _feedback7,
                _feedback8
            };
        }


        public SVHControllerFeedbackAllChannels(byte[] data)
        {
            int dim = (int)SVHConstants.SVHChannel.eSVH_DIMENSION;
            feedbacks = new SVHControllerFeedback[dim];
            for (int i = 0; i < dim; ++i)
            {
                feedbacks[i] = new SVHControllerFeedback(BitConverter.ToInt32(data, 4 * i), BitConverter.ToInt16(data,36+2*i));
            }
        }


    }

}
